#ifndef __ATMOS_PacketListener_h__
#define __ATMOS_PacketListener_h__

#include "ATMOS_Common.h"
#include "ATMOS_AutoHandler.h"

#include <map>

namespace ATMOS {	

/*! \brief Base class for classes that want to receive network notifications and packets
	*	
	*	This class is a base class that must be used by any classes that want to receive network
	*	events and packets.
	*	
	*	After construction, the PacketListener-derived class must be registered with a 
	*	NetworkManager instance in order to receive network notifications.
	*	
	*	It is technically possible to register a single PacketListener instances with multiple
	*	network managers, however this is not advised as there is no way to tell which of the 
	*	multiple network managers called the handler function.  A better alternative is demonstrated
	*	in the Demo_Server program included with this library.
	*/
class AtmosExport PacketListener
{
public:
	//! the preferred constructor for PacketListener
	/*! 
		\param networkManager optional, the network manager instance associated with this listener
		*/
	PacketListener( NetworkManager *networkManager );
	PacketListener();
	~PacketListener();
				
	//! get the NetworkManager associated with this listener, may be null
	NetworkManager *getNetworkManager();
		
	virtual void onAtmosPacket( Packet *packet ) = 0;		
	virtual void onDisconnectionNotification( const std::string &senderGUID ){}
	virtual void onAlreadyConnected( const std::string &senderGUID ){}
	virtual void onIncompatibleProtocolVersion( const std::string &senderGUID ){}
	virtual void onRemoteDisconnectionNotification( const std::string &senderGUID ){}
	virtual void onRemoteConnectionLost( const std::string &senderGUID ){}
	virtual void onNewIncomingConnection( const std::string &senderGUID ){}
	virtual void onConnectionBanned( const std::string &senderGUID ){}
	virtual void onConnectionAttemptFailed( const std::string &senderGUID ){}
	virtual void onNoFreeIncomingConnections( const std::string &senderGUID ){}
	virtual void onInvalidPassword( const std::string &senderGUID ){}
	virtual void onConnectionLost( const std::string &senderGUID ){}
	virtual void onConnectionRequestAccepted( const std::string &senderGUID ){}
	virtual void onUnknownPacket( const std::string &senderGUID ){}

protected:
	//! set the network manager, may be null
	void _setNetworkManager( NetworkManager *networkManager );

private:
	NetworkManager *mNetworkManager;
};

} // end namespace ATMOS

#endif